package com.zzyl.service.impl;

import com.zzyl.dto.LoginDto;
import com.zzyl.mapper.LoginMapper;
import com.zzyl.properties.JwtTokenManagerProperties;
import com.zzyl.service.LoginService;
import com.zzyl.utils.JwtUtil;
import com.zzyl.vo.UserVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description LoginService
 * @Author zpf
 * @Date 2024-08-28
 */
@Service
@Slf4j
public class LoginServiceImpl implements LoginService {
     @Autowired
     private LoginMapper loginMapper;

     @Autowired
     private JwtTokenManagerProperties jwtTokenManagerProperties;


     /**
      * 登录
      *
      * @param loginDto
      * @return
      */
     @Override
     public UserVo login(LoginDto loginDto) {
          UserVo userVo = new UserVo();
          Map<String,Object> map = new HashMap<>();
          map.put("username",loginDto.getUsername());
//          map.put("password",loginDto.getPassword());
          String username = loginDto.getUsername();
          userVo= loginMapper.log(username);
          String usertoken = JwtUtil.createJWT(jwtTokenManagerProperties.getBase64EncodedSecretKey(), jwtTokenManagerProperties.getTtl(), map);
          userVo.setUserToken(usertoken);
          return userVo;
     }
}
